# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

# include kernel/user

LIBINCLUDE	+= include/

LIBCFLAGS   := -fno-builtin -nostdinc -m32 -Iarch/$(ARCH)/include -Iarch/$(ARCH)/drivers -Darch_$(ARCH)
LIBCFLAGS	+= $(addprefix -I,$(LIBINCLUDE))

LIBDIR	+= lib_common

$(call add_files_cc,$(call listf_cc,$(LIBDIR)),libs, $(LIBCFLAGS))

# -------------------------------------------------------------------

# common part of the kernel

SRCDIR		+= lib 			 \
			   kernel        \
			   mm 			 \
			   fs

$(call add_files_cc,$(call listf_cc,$(SRCDIR)),kernel,$(CFLAGS) -fno-builtin -Iarch/$(ARCH)/include -Iarch/$(ARCH)/drivers -Darch_$(ARCH))

OBJS	= $(call read_packet,kernel libs)

# -------------------------------------------------------------------
# user programs

UINCLUDE	+= user/include/ \
			   user/libs/

USRCDIR		+= user

ULIBDIR		+= user/libs

UCFLAGS		+= $(addprefix -I,$(UINCLUDE))
UCFLAGS		+= -fno-builtin -m32 -gstabs -nostdinc -ggdb
USER_BINS	:=

$(call add_files_cc,$(call listf_cc,$(ULIBDIR)),ulibs,$(UCFLAGS))
$(call add_files_cc,$(call listf_cc,$(USRCDIR)),uprog,$(UCFLAGS))

UOBJS	:= $(call read_packet,ulibs libs)

define uprog_ld
__user_bin__ := $$(call ubinfile,$(1))
USER_BINS += $$(__user_bin__)
$$(__user_bin__): tools/user.ld
$$(__user_bin__): $$(UOBJS)
$$(__user_bin__): $(1) | $$$$(dir $$$$@)
	$(V)$(LD) $(LDFLAGS) -T tools/user.ld -o $$@ $$(UOBJS) $(1)
endef

$(foreach p,$(call read_packet,uprog),$(eval $(call uprog_ld,$(p))))

# -------------------------------------------------------------------
